<template>
    <div>
        <el-button type="info" icon="el-icon-back" circle style="margin-left:-900px "
                   @click="$router.push({path:'/tc_shopmall_tj'})">返回销售
        </el-button>
        <div>
            收&nbsp;&nbsp;&nbsp;款:
            <el-input
                    placeholder="请输入金额"
                    v-model="sk"
                    clearable
                    :on-icon-click="pchandleIconClick" @keyup.enter.native="searchEnterFun">
            </el-input>
            <br/>

            找&nbsp;&nbsp;&nbsp;零:
            <el-input
                    placeholder="找零"
                    v-model="zl"
                    :disabled="true">
            </el-input>
            <br/>
            会员号:
            <el-input
                    placeholder="非会员可不填写"
                    v-model="updateOrder.membernumber">
            </el-input>
            <br/>
            <div><label v-for="(item,index) in radioData" :key="index"> <input @click="getRadioVal" type="radio"
                                                                               name="type"
                                                                               :value="item.value">{{item.value}} </label>
            </div>

        </div>
        <a>订单总价:<a style="font-size:25px;color: orangered">{{this.$route.query.pricetotal}}</a>(结账总价大于等于100元可将成为会员!)</a><br/>
        <el-button type="info" plain @click="qdzf()">确定支付</el-button>
        <el-button type="text" @click="hy()" :plain="true">添加会员</el-button>
        <h2 style="font-family: 华文彩云">请确认付款货币为真币时再确认支付,否则一切损失由个人承担!</h2>
    </div>

</template>

<script>
    import ElButton from "../../../node_modules/element-ui/packages/button/src/button.vue";

    export default {
        components: {ElButton},
        data() {
            return {
                sk: '',
                zl: '',
                kc: {
                    quantity: ''
                },
                radioData: [
                    {value: '现金'},
                    {value: '微信'},
                    {value: '支付宝'}
                ],
                updateOrder: {
                    membernumber: "",//会员号
                    paytype: "",
                    state: 1,
                    orderid:"",//订单id
                    memberintegeral:this.$route.query.pricetotal*0.1//会员积分
                }
            }

        },

        beforeRouteEnter(to, from, next) {
            // 在渲染该组件的对应路由被 confirm 前调用
            // 不！能！获取组件实例 `this`
            // 因为当钩子执行前，组件实例还没被创建
            // alert("home被显示");
            next(vm => {
                //在此处vm表示vue组件对象
                vm.loadData();

            });
        },
        methods: {
            loadData: function () {
                this.axios.post('Http://localhost:8686/selectOneOrderId')
                    .then((response) => {
                      alert(response.data)
                        this.updateOrder.orderid=response.data;
                    }).catch((error) => {
                    this.$message.success("错误!")
                })
            }, searchEnterFun: function (e) {
                if (this.sk < this.$route.query.pricetotal) {
                    this.$message.warning("请输入正确金额!")
                } else {
                    this.zl = this.sk - this.$route.query.pricetotal;
                }

            },

            getRadioVal(event) { //event当前事件对象
                // var radioVal = event.target.value;
                this.updateOrder.paytype = event.target.value;
                alert(this.updateOrder.paytype)
            },
            qdzf: function () {
                if(this.updateOrder.membernumber!=null||this.updateOrder.membernumber!=""){
                    this.axios.post('/updateOrder', this.updateOrder)
                    //alert("进入跨域修改controller")
                        .then((response) => {
                            if(response.data>0){
                                this.$message.success("支付成功!")
                            }else {
                                this.$message.success("失败!")
                            }
                        }).catch((error) => {
                        this.$message.success("系统错误!"+error)
                    })
                    this.axios.post('/updateScoreByMemNumber',this.updateOrder)
                        .then((response) => {
                            if(response.data>0){
                                this.$message.success("会员积分添加成功!")
                            }else {
                                this.$message.success("会员积分添加失败!")
                            }
                        }).catch((error) => {
                        this.$message.success("会员积分添加系统错误!"+error)
                    })
                }else{
                    this.axios.post('/updateOrder', this.updateOrder)
                    //alert("进入跨域修改controller")
                        .then((response) => {
                            if(response.data>0){
                                this.$message.success("支付成功!")
                            }else {
                                this.$message.success("失败!")
                            }
                        }).catch((error) => {
                        this.$message.success("系统错误!"+error)
                    })
                }

            },
            hy: function () {
                if (this.$route.query.pricetotal >= 100) {
                    this.$router.push({path: '/tc_shopmall_insertHy'});
                } else {
                    this.$message({
                        showClose: true,
                        message: '消费未满100元，不能成为会员！',
                        type: 'warning'
                    });
                }
            },


        }

    }
</script>

<style scoped>
    .el-input {
        width: 180px;
    }
</style>
